Commits

Anonymous committed 8c68ae7

applying per-site settings on URL match and reverting when visiting
another site

Comments (0)

Files changed (2)

 void fill_suggline(char * suggline, const char * command, const char *fill_with);
 GtkWidget * fill_eventbox(const char * completion_line);
 static void mop_up(void);
+void apply_settings(char *uri);
 
 #include "main.h"
 
 char *config_base = NULL;
 static gboolean manual_focus = FALSE;
 
-GList *activeDownloads;
+GList *activeDownloads, *siteSettings = NULL;
+char backupsettings[MAX_SETTING_SIZE] = "";
 
 #include "config.h"
 #include "keymap.h"
                 memcpy(&new[sizeof("http://") - 1], s, len + 1);
             }
         }
+        apply_settings(new);
         webkit_web_view_load_uri(webview, new);
         g_free(new);
     } else
 #endif
 
 void
+apply_settings(char *uri) {
+    SSettings *s;
+    GList *l;
+    char temp[MAX_SETTING_SIZE], *temp2, temp3[MAX_SETTING_SIZE];
+    guint i, j, len, len2, len3;
+
+    /* check for site-specific settings */
+    if (siteSettings != NULL) {
+        len = g_list_length(siteSettings);
+        for (i = 0; i < len; i++) {
+            l = g_list_nth(siteSettings, i);
+            s = (SSettings *)l->data;
+            if (strlen(uri) >= strlen(s->url) && strncmp(s->url, uri, strlen(s->url)) == 0) {
+      	        /* match found */
+      	        memset(temp, 0, MAX_SETTING_SIZE);
+      	        strncpy(temp, s->settings, MAX_SETTING_SIZE);
+      	        temp2 = strtok(temp, "|");
+      	        while (temp2 != NULL) {
+      	            /* remember current standard settings */
+      	            memset(temp3, 0, MAX_SETTING_SIZE);
+      	            len2 = strcspn(temp2, "=");
+      	            len3 = LENGTH(browsersettings);
+      	            for (j = 0; j < len3; j++) {
+                        if (strlen(browsersettings[j].name) == len2 && strncmp(browsersettings[j].name, temp2, len2) == 0)  {
+                            strncat(backupsettings, "|", 1);
+                            strncat(backupsettings, temp2, len2 + 1);
+                            strncat(backupsettings, browsersettings[j].var, strlen(browsersettings[j].var));
+      	                }
+      	            }
+      	            /* apply the setting */
+      	            process_set_line(temp2);
+      	            temp2 = strtok(NULL, "|");
+      	        }
+      	        return;
+      	    }
+      	}
+      	if (strlen(backupsettings) > 0) {
+            /* revert to standard settings
+             * the string has to be applied from right to left
+             * this ensures that if various values have been set for the same key in the meantime,
+             * we will still get back to the most basic state
+             */
+            temp2 = strrchr(backupsettings, '|');
+            while (temp2 != NULL) {
+                process_set_line(temp2 + 1);
+                memset(temp2, 0, strlen(temp2));
+                temp2 = strrchr(backupsettings, '|');
+            }
+            /* erase remembered settings */
+            memset(backupsettings, 0, MAX_SETTING_SIZE);
+        }
+    }
+}
+
+void
 mop_up(void) {
 	/* Free up any nasty globals before exiting. */
 #ifdef ENABLE_COOKIE_SUPPORT
 #include "main.h"
 #include "utilities.h"
 
-extern GList *commandhistory;
+extern GList *commandhistory, *siteSettings;
 extern int commandpointer;
 extern Command commands[COMMANDSIZE];
 extern KeyList *keylistroot;
 extern char *error_msg;
 extern char *config_base;
 extern VSettings cursettings;
-static GList *dynamic_searchengines = NULL, *dynamic_uri_handlers = NULL, *site_settings = NULL;
+static GList *dynamic_searchengines = NULL, *dynamic_uri_handlers = NULL;
 
 void add_modkeys(char key);
 
 			}
 			newsettings->url = g_strdup(buffer);
 			newsettings->settings = g_strdup(buffer+index);
-			site_settings = g_list_prepend(site_settings, newsettings);
+			siteSettings = g_list_prepend(siteSettings, newsettings);
 		} else if (strncmp(s, "searchengine", 12) == 0) {
 			buffer = (s + 12);
 			while (buffer[0] == ' ')
     }
     return FALSE;
 }
-