--- load-applet-0.4.4-2/load-applet.c	2006-06-19 20:59:41.000000000 +0200
+++ load-applet-aw-0.4.4-2-0.1/load-applet.c	2006-06-20 17:35:00.000000000 +0200
@@ -47,9 +47,13 @@
 #include <dirent.h>
 #include <libosso.h>
 
+/* Application settings */
+#include <gconf/gconf-client.h>
+
 #include <hildon-widgets/gtk-infoprint.h>
 #include <hildon-status-bar-lib/hildon-status-bar-item.h>
 #include <hildon-widgets/hildon-input-mode-hint.h>
+#include <hildon-widgets/hildon-note.h>
 
 #define DBUS_API_SUBJECT_TO_CHANGE
 #include <dbus/dbus.h>
@@ -93,6 +97,7 @@
     GtkWidget *menu_separator;
     GtkWidget *menu_screenshot;
     GtkWidget *menu_delayed_screenshot;
+    GtkWidget *menu_swap;
     GtkWidget *menu_settings;
     gboolean in_area;
     gboolean on_border;
@@ -111,16 +116,26 @@
 static int width, height;
 #define MAX_READ_CHARS 128
 static char read_buffer[MAX_READ_CHARS];
+static char dummy[MAX_READ_CHARS];
+#define MAX_SWAPNAME 64
+static char activeswapname[MAX_SWAPNAME];
+static gint swapused=0;
+static char label[64+MAX_SWAPNAME];
 #define MAX_SSHOT_NAME_LEN 64
 #define SSHOT_DEFAULT_NAME "screenshot"
 static gchar *sshotfilename = NULL;
+static gchar *swapname = NULL;
 static char sshotname[MAX_SSHOT_NAME_LEN];
 
 static gint screenshot_delay = 7;
+
+/* defined but not used:
 static gboolean include_system = TRUE;
 static gboolean include_user = TRUE;
 static gboolean include_io = TRUE;
+*/
         
+static GConfClient *gc_client;
 
 /* Hildon Status Bar plugin API prototypes */
 void *load_initialize(HildonStatusBarItem *item, GtkWidget **button);
@@ -133,7 +148,25 @@
 /* Internal function prototypes */
 static gboolean check_load_cpu (gpointer);
 
-
+static gboolean
+swapisactive(void)
+{ /* side-effect: update global var swapused, if swap is active */
+  FILE *fin;
+
+  swapused=0;
+  fin = fopen(SWAPFILE, "r");
+  if (fin == NULL) g_error("Can't open "SWAPFILE"\n");
+  if (! fgets(read_buffer, MAX_READ_CHARS, fin)) /* skip 1st line */
+    return FALSE;
+  while (fgets(read_buffer, MAX_READ_CHARS, fin) && swapname) {
+    if (read_buffer) {
+      sscanf(read_buffer, "%s %s %s %d", activeswapname, dummy, dummy, &swapused);
+      if (strncmp(activeswapname, swapname, MAX_SWAPNAME) == 0)
+        return TRUE;
+    }
+  }
+  return FALSE;
+}
 
 static void close_window()
 {
@@ -313,7 +346,9 @@
     
    
     g_object_unref (pixbuf);
-    sshotn++;
+    if (sshotn++ == 99)
+	    sshotn = 0;
+    gconf_client_set_int(gc_client, "/apps/maemo/loadapplet/screenshot_number", sshotn, NULL);
 
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(info->button), FALSE);
 
@@ -321,6 +356,28 @@
 }
 
 static void
+activate_swap_item(GtkMenuItem *item, gpointer data)
+{
+  GtkWidget *confirm;
+  gint result;
+
+  if (swapname && *swapname)
+  {
+    if (swapisactive())
+      sprintf(label, "/usr/bin/sudo /sbin/swapoff %s", swapname);
+    else
+      sprintf(label, "/usr/bin/sudo /sbin/swapon %s", swapname);
+
+    confirm = hildon_note_new_confirmation(NULL, label);
+    result = gtk_dialog_run (GTK_DIALOG (confirm));
+    gtk_widget_destroy (GTK_WIDGET (confirm));
+
+    if (result == GTK_RESPONSE_OK)
+      system(label);
+  }
+}
+
+static void
 activate_screenshot_item(GtkMenuItem *item, gpointer data)
 {
     make_screenshot();
@@ -351,7 +408,7 @@
         GtkWidget *vbox, *hboxtop, *hboxbottom;
         GtkWidget *labeldelay, *labelfilename;
         GtkWidget *sb_seconds;
-	GtkWidget *entry_filename;
+	GtkWidget *entry_filename, *entry_filename2;
         gint result;
 
         dialog = gtk_dialog_new_with_buttons ("Screenshot settings",
@@ -410,6 +467,27 @@
                             TRUE,
                             5);
 
+       /* swap name */
+       hboxbottom = gtk_hbox_new (FALSE, 5);
+       gtk_box_pack_start (GTK_BOX(vbox),
+                           hboxbottom,
+                           TRUE,
+                           TRUE,
+                           2);
+       labelfilename = gtk_label_new ("Swap device");
+       gtk_box_pack_start (GTK_BOX(hboxbottom),
+                           labelfilename,
+                           TRUE,
+                           TRUE,
+                           5);
+       entry_filename2 = gtk_entry_new_with_max_length(MAX_SSHOT_NAME_LEN - 5);
+       gtk_entry_set_text(GTK_ENTRY(entry_filename2), swapname);
+       gtk_box_pack_start (GTK_BOX(hboxbottom),
+                           entry_filename2,
+                           TRUE,
+                           TRUE,
+                           5);
+
         gtk_widget_show_all(dialog);
 
         result = gtk_dialog_run (GTK_DIALOG (dialog));
@@ -423,6 +501,18 @@
                if (sshotfilename) g_free(sshotfilename);
                sshotfilename = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_filename)));
                screenshot_delay = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(sb_seconds));
+	       /* Save new swapdev name */
+	       if (swapname) g_free(swapname);
+	           swapname = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_filename2)));
+
+               /* make settings persistent via gconf */
+               gconf_client_set_string(gc_client, "/apps/maemo/loadapplet/sshotfilename", 
+			       sshotfilename, NULL);
+               gconf_client_set_int(gc_client, "/apps/maemo/loadapplet/screenshot_delay", 
+			       screenshot_delay, NULL);
+               gconf_client_set_string(gc_client, "/apps/maemo/loadapplet/swapname", 
+			       swapname, NULL);
+
                gtk_widget_destroy(dialog);
                break;
         default:
@@ -443,7 +533,15 @@
 static void 
 load_icon_pressed(GtkWidget *widget, gpointer data)
 {
-    if (!GTK_IS_MENU(info->menu)) 
+    if (GTK_IS_MENU(info->menu)) { /* is this a memory leak??? */
+           gtk_widget_destroy(info->menu_screenshot);
+           gtk_widget_destroy(info->menu_delayed_screenshot);
+           gtk_widget_destroy(info->menu_separator);
+           gtk_widget_destroy(info->menu_swap);
+           gtk_widget_destroy(info->menu_settings);
+           gtk_widget_destroy(info->menu);
+    }
+    if (1 == 1)
     {
         info->menu = gtk_menu_new();
 
@@ -467,6 +565,24 @@
         info->menu_separator = gtk_separator_menu_item_new();
         gtk_menu_shell_append(GTK_MENU_SHELL(info->menu),
                         info->menu_separator);
+
+        /* Swap */
+	if (swapname && *swapname) {
+          if (swapisactive())
+            sprintf(label, "swapoff %s (%d MB used)", swapname, (swapused+512)/1024);
+          else
+            sprintf(label, "swapon %s", swapname);
+          info->menu_swap = gtk_menu_item_new_with_label(label);
+          gtk_menu_shell_append(GTK_MENU_SHELL(info->menu),
+                               info->menu_swap);
+          g_signal_connect(G_OBJECT(info->menu_swap),
+                          "activate",
+                          G_CALLBACK(activate_swap_item),
+                          data);
+        }
+        else
+          info->menu_swap = NULL;
+
         /* Settings */
         info->menu_settings = gtk_menu_item_new_with_label("Settings");
         gtk_menu_shell_append(GTK_MENU_SHELL(info->menu),
@@ -519,8 +635,10 @@
     int load, idle;
     int memfree = 0;
     int memtotal = 0;
+    /* unused:
     int swap_total = 0;
     int swap_used = 0;
+    */
     char digits[MAX_DIGITS_CHARS];
     char *position;
     int ww, hh, xx, yy;
@@ -631,32 +749,14 @@
          gdk_pixbuf_composite(info->pixbuf_high, info->pixbuf_current, xx,yy,ww,hh, 0,0,1,1,GDK_INTERP_NEAREST, 255);
     }
     /*
-     * If the SWAP is on and used, indicate that on top of the memory icon
+     * If the SWAP is on, indicate that on top of the memory icon
      */
-    fin = fopen(SWAPFILE, "r");
-    if (fin != NULL)
+    if (swapisactive())
     {
-        /* Do this only if there is the file and it can be open */
-        while (fgets(read_buffer, MAX_READ_CHARS, fin) != NULL)
-        {
-            char* pointer = NULL;
-    
-            pointer = strstr(read_buffer, "/media/mmc");
-    
-            if (pointer) pointer = strstr(read_buffer, "file");
-            
-            if (pointer)
-            {
-                /* This should be the line with our SWAP on MMC */
-                sscanf(pointer + strlen("file"), "%d %d", &swap_total, &swap_used);
-                if (swap_used > 0)
-                {
-                    /* We are using the SWAP, show it */
-                    gdk_pixbuf_composite(info->pixbuf_swap_on, info->pixbuf_current, 20, 22, 20, 18, 20, 22, 1, 1, GDK_INTERP_NEAREST, 255);
-                }
-            }
-        }
-        fclose(fin);
+        /* We have the SWAP active and are using the SWAP, show it */
+        gdk_pixbuf_composite(info->pixbuf_swap_on, info->pixbuf_current, 
+			20, 22, 20, 18, 20, 22, 1, 1, GDK_INTERP_NEAREST, 255);
+
     }
     /* 
      * Set the icon from the current pixmap 
@@ -768,7 +868,19 @@
     /* Screenshot stuff too */
     root_window = gdk_get_default_root_window ();
     gdk_drawable_get_size (root_window, &width, &height);
-    sshotfilename = g_strdup(SSHOT_DEFAULT_NAME);
+
+    /* retrieve stored settings from gconf */
+    g_type_init();
+    gc_client = gconf_client_get_default();
+    if (! (sshotfilename = gconf_client_get_string(gc_client, 
+		    "/apps/maemo/loadapplet/sshotfilename", NULL)))
+      sshotfilename = g_strdup(SSHOT_DEFAULT_NAME);
+    screenshot_delay = gconf_client_get_int(gc_client, 
+		    "/apps/maemo/loadapplet/screenshot_delay", NULL);
+    swapname = gconf_client_get_string(gc_client, 
+		    "/apps/maemo/loadapplet/swapname", NULL);
+    sshotn = gconf_client_get_int(gc_client, "/apps/maemo/loadapplet/screenshot_number", NULL);
+    
     return info;
 }
 
--- load-applet-0.4.4-2/configure.ac	2006-06-19 20:59:40.000000000 +0200
+++ load-applet-aw-0.4.4-2-0.1/configure.ac	2006-06-20 12:05:40.000000000 +0200
@@ -42,6 +42,10 @@
 AC_SUBST(HILDON_LIBS)
 AC_SUBST(HILDON_CFLAGS)
 
+PKG_CHECK_MODULES(GCONF, gconf-2.0 >= 2.6.2)
+AC_SUBST(GCONF_LIBS)
+AC_SUBST(GCONF_CFLAGS)
+
 ALL_LINGUAS="de_DE en_GB en_US es_ES es_MX fi_FI fr_CA fr_FR it_IT pt_BR ru_RU"
 AC_SUBST(ALL_LINGUAS)
 
--- load-applet-0.4.4-2/Makefile.am	2006-06-19 20:59:41.000000000 +0200
+++ load-applet-aw-0.4.4-2-0.1/Makefile.am	2006-06-20 12:20:56.000000000 +0200
@@ -1,6 +1,6 @@
 SUBDIRS = 
 
-INCLUDES = $(STATUSBARLIB_CFLAGS) $(GTK_CFLAGS) $(HILDON_CFLAGS) $(DBUS_CFLAGS)\
+INCLUDES = $(STATUSBARLIB_CFLAGS) $(GTK_CFLAGS) $(HILDON_CFLAGS) $(DBUS_CFLAGS) $(GCONF_CFLAGS) \
 	-DPREFIX=\"$(prefix)\" -DLOCALEDIR=\"$(localedir)\"
 AM_LDFLAGS = -module -avoid-version
 
@@ -20,7 +20,7 @@
 	$(icon_DATA)
 
 hildonstatusbarplugin_LTLIBRARIES = libload.la 
-libload_la_LIBADD = $(STATUSBARLIB_LIBS) $(GTK_LIBS) $(HILDON_LIBS)
+libload_la_LIBADD = $(STATUSBARLIB_LIBS) $(GTK_LIBS) $(HILDON_LIBS) $(GCONF_LIBS)
 libload_la_SOURCES = load-applet.c 
 
 load_applet_desktop_DATA=load-applet.desktop

