Changeset 544


Ignore:
Timestamp:
11/27/13 15:29:04 (10 years ago)
Author:
jts21
Message:

Updated JfxBrowser to use search engine variable, and also fixed some logic errors in it

Location:
trunk/src/org/expeditee
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r542 r544  
    709709                                } else if (attribute.equals("proxy")) {
    710710                                        proxySetup(item);
     711                                } else if (attribute.equals("settings")) {
     712                                        generalSetup(item);
    711713                                } else if (attribute.equals("fillcolorwheel")) {
    712714                                        Item.FILL_COLOR_WHEEL = getColorWheel(item);
     
    736738                return errors;
    737739        }
     740       
     741        /**
     742         * Loads general config from a frame
     743         * @author jts21
     744         */
     745        private static void generalSetup(Item item) {
     746                try {
     747                        Frame child = item.getChild();
     748                        String str, strLower;
     749                        String searchEngine = "";
     750                        // gather all the settings
     751                        for(Item config : child.getAllItems()) {
     752                                if(config instanceof Text) {
     753                                        str = config.getText().trim();
     754                                        strLower = str.toLowerCase();
     755                                        if(strLower.startsWith("searchengine:")) {
     756                                                searchEngine = str.substring(13).trim();
     757                                        }
     758                                }
     759                        }
     760                        // set all the settings to their defined values or their defaults
     761                        if(searchEngine.length() == 0 || searchEngine.toLowerCase().equals("default")) {
     762                                UserSettings.searchEngine = UserSettings.defaultSearchEngine;
     763                                MessageBay.displayMessage("Defaulted search engine to " + UserSettings.searchEngine);
     764                        } else {
     765                                UserSettings.searchEngine = searchEngine;
     766                                MessageBay.displayMessage("Set search engine to " + UserSettings.searchEngine);
     767                        }
     768                } catch(Exception e) {
     769                        System.err.println("Failed to load config");
     770                        e.printStackTrace();
     771                }
     772        }
    738773
    739774        /**
     
    748783                        for(Item config : child.getAllItems()) {
    749784                                if(config instanceof Text) {
    750                                         String str = config.getText().trim().toLowerCase();
    751                                         if(str.startsWith("host:")) {
     785                                        String str = config.getText().trim();
     786                                        String strLower = str.toLowerCase();
     787                                        if(strLower.startsWith("host:")) {
    752788                                                if(host != null) {
    753789                                                        MessageBay.displayMessage("host was defined multiple times!", Color.ORANGE);
    754790                                                }
    755791                                                host = str.substring(5).trim();
    756                                         } else if(str.startsWith("port:")) {
     792                                        } else if(strLower.startsWith("port:")) {
    757793                                                if(port!= null) {
    758794                                                        MessageBay.displayMessage("port was defined multiple times!", Color.ORANGE);
    759795                                                }
    760796                                                port = str.substring(5).trim();
    761                                         } else if(str.startsWith("user:")) {
     797                                        } else if(strLower.startsWith("user:")) {
    762798                                                if(user != null) {
    763799                                                        MessageBay.displayMessage("user was defined multiple times!", Color.ORANGE);
    764800                                                }
    765801                                                user = str.substring(6).trim();
    766                                         } else if(str.startsWith("pass:")) {    // unencrypted password
     802                                        } else if(strLower.startsWith("pass:")) {       // unencrypted password
    767803                                                if(pass != null) {
    768804                                                        MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
    769805                                                }
    770806                                                pass = str.substring(6).trim();
    771                                         } else if(str.startsWith("@iw:")) {             // widget
     807                                        } else if(strLower.startsWith("@iw:")) {                // widget
    772808                                                // check if it's a password widget
    773                                                 if(str.substring(4).trim().startsWith("org.expeditee.items.widgets.password")) {
     809                                                if(strLower.substring(4).trim().startsWith("org.expeditee.items.widgets.password")) {
    774810                                                        if(passwordWidget == null) {
    775811                                                                try {
  • trunk/src/org/expeditee/gui/UserSettings.java

    r504 r544  
    7070
    7171        public static Text StatTemplate = null;
     72       
     73        // The URL to prepend to web searches
     74        public static final String defaultSearchEngine = "https://duckduckgo.com/?q=";
     75        public static String searchEngine = defaultSearchEngine;
    7276
    7377        // add default values
  • trunk/src/org/expeditee/items/widgets/JfxBrowser.java

    r543 r544  
    1919import org.expeditee.gui.FreeItems;
    2020import org.expeditee.gui.MessageBay;
     21import org.expeditee.gui.UserSettings;
    2122import org.expeditee.items.Text;
    2223
     
    292293                        // TODO: can/should we support other protocols such as ftp ???
    293294                        if(!(textLower.startsWith("http://") || text.startsWith("https://"))) {
    294                                 // check if it's a search (will be a search if there is a ' ' before the first '.')
    295                                 // TODO: maybe support changing the default search engine (using a settings frame like the proxy settings frame)
     295                                // check if it's a search
    296296                                int firstSpace = text.indexOf(" ");
    297297                                int firstDot = text.indexOf(".");
    298                                 if(firstSpace != -1 && firstSpace < firstDot) {
     298                                int firstSlash = text.indexOf('/');
     299                                int firstQuestion = text.indexOf('?');
     300                                if(firstDot == -1 ||                                        // no '.' and no protocol -> search
     301                                        (firstSpace != -1 && firstSpace <= firstDot + 1) || // ' ' before '.'         -> search
     302                                        (firstSlash == -1 && firstQuestion == -1)) {        // no '/' or '?'          -> search
    299303                                        // make it a search
    300                                         text = "https://duckduckgo.com/?q=" + text;
     304                                        text = UserSettings.searchEngine + text;
    301305                                } else {
    302306                                        // add the missing protocol
Note: See TracChangeset for help on using the changeset viewer.