📄 profilemanager.java
字号:
} /** * Loads a profile * * @param profile * the profile to load */ public static void loadProfile(String profile) { Settings.loadSettings(profDir.getPath() + File.separatorChar + profile, "settings.properties"); if (JBother.kiosk_mode && Arguments.getInstance().getProperty("kiosk_roomservice") != null) { Settings.createKioskRoom(); } JBother.profileDir = JBother.settingsDir + File.separatorChar + "profiles" + File.separatorChar + profile; GnuPG gnupg = new GnuPG(); JBotherLoader.setGPGEnabled(gnupg.listKeys("")); String fontString = Settings.getInstance().getProperty( "applicationFont"); if (fontString == null) { fontString = "Default-PLAIN-12"; } Font newFont = Font.decode(fontString); com.valhalla.jbother.preferences.AppearancePreferencesPanel .updateApplicationFonts(newFont, null); ConversationFormatter.getInstance().switchTheme( Settings.getInstance().getProperty("emoticonTheme")); StatusIconCache.clearStatusIconCache(); BuddyList.getInstance().loadSettings(); JBotherLoader.loadSettings(); if (JBotherLoader.isGPGEnabled() && Settings.getInstance().getBoolean("gnupgSavePassphrase") && Settings.getInstance().getProperty("gnupgSecretKeyID") != null) { String pass = Settings.getInstance().getProperty("gnupgPassPhrase"); if (pass == null) pass = ""; pass = SimpleXOR.decrypt(pass, "86753099672539"); gnupg = new GnuPG(); String gnupgSecretKeyID = Settings.getInstance().getProperty( "gnupgSecretKeyID"); if (gnupg.sign("1", gnupgSecretKeyID, pass)) { BuddyList.getInstance().setGnuPGPassword(pass); } else { BuddyList.getInstance().setGnuPGPassword(null); Standard.warningMessage(null, "GnuPG", resources .getString("gnupgBadSavedPassword")); } } if (Settings.getInstance().getBoolean("autoLogin")) { ConnectorThread.getInstance().setCancelled(false); ConnectorThread.getInstance().init(Presence.Mode.AVAILABLE, "Available", false).start(); } if (Settings.getInstance().getBoolean("useProxy")) { Properties sysProperties = System.getProperties(); sysProperties.setProperty("proxySet", "true"); sysProperties.setProperty("proxyHost", Settings.getInstance().getProperty("proxyHost")); sysProperties.setProperty("proxyPort", Settings.getInstance().getProperty("proxyPort")); } currentProfile = profile; } /** * Loads a list of profiles */ protected void loadProfileList() { if (!profDir.isDirectory() && !profDir.mkdirs()) { com.valhalla.Logger .debug("Could not create profile directory! Please check permissions on ~/.jbother"); System.exit(-1); } model = new ProfileListModel(); String list[] = profDir.list(new FilenameFilter() { public boolean accept(File dir, String name) { if (new File(dir, name).isDirectory()) { return true; } else { return false; } } }); for (int i = 0; i < list.length; i++) { model.addElement(list[i]); } profileList.setModel(model); selectDefault(); } /** * Selects the default profile and labels it (default) */ private void selectDefault() { String defaultProfile = getDefaultProfile(); if (defaultProfile == null) { setDefaultProfile(defaultProfile); return; } boolean def = true; if(selected != null && model.indexOf(selected) != -1) defaultProfile = (String)selected; int index = model.indexOf(defaultProfile); if (index != -1) { profileList.setSelectedIndex(index); } else { profileList.setSelectedIndex(0); } } /** * Gets the current default profile, or the first profile in the profiles * directory * * @return The default profile */ public static String getDefaultProfile() { File file = new File(profDir, "default.properties"); if (!file.exists()) { return getOnlyProfile(); } Properties def = new Properties(); try { InputStream stream = new FileInputStream(file); def.load(stream); stream.close(); } catch (IOException e) { com.valhalla.Logger.logException(e); return getOnlyProfile(); } return def.getProperty("defaultProfile"); } /** * Gets the first profile in the profile directory * * @return The first profile in the profile directory, or <tt>null</tt> if * there are no profiles */ public static String getOnlyProfile() { if (JBother.kiosk_mode) return Arguments.getInstance().getProperty("kiosk_user"); String[] list = profDir.list(); if (list != null && list.length > 0) { return list[0]; } else { return null; } } /** * Sets the default profile * * @param profile * The profile to set */ public static void setDefaultProfile(String profile) { File file = new File(profDir, "default.properties"); try { OutputStream stream = new FileOutputStream(file); Properties def = new Properties(); def.setProperty("defaultProfile", profile); def.store(stream, "default profile setting"); stream.close(); } catch (Exception e) { com.valhalla.Logger.logException(e); } } class ListRenderer extends JLabel implements ListCellRenderer { public ListRenderer() { setOpaque(true); } public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String def = getDefaultProfile(); setSelected(isSelected); String val = (String)value; if(def.equals(val)) val += defaultString; setText(val); return this; } public void setSelected(boolean selected) { if(selected) setBackground(profileList.getSelectionBackground()); else setBackground(Color.WHITE); } } /** * The JList model for the profiles list * * @author synic * @created November 30, 2004 */ class ProfileListModel extends DefaultListModel { /** * Sets the valueAt attribute of the ProfileListModel object * * @param index * The new valueAt value * @param value * The new valueAt value */ public void setValueAt(int index, String value) { model.removeElementAt(index); model.insertElementAt(value, index); fireContentsChanged(model, index, index + 1); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -