OSX: new hide from Dock setting available directly in UI (DavMail restart needed)

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1958 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2012-05-10 22:49:46 +00:00
parent 7d6ee0d27e
commit 6d02a25c0e
6 changed files with 140 additions and 9 deletions

View File

@ -109,13 +109,8 @@
</jarfileset>
</jarbundler>
<!-- prepare hide from dock option -->
<copy file="dist/DavMail.app/Contents/Info.plist" tofile="dist/DavMail.app/Contents/Info-dock.plist"/>
<copy file="dist/DavMail.app/Contents/Info.plist" tofile="dist/DavMail.app/Contents/Info-nodock.plist"/>
<replaceregexp file="dist/DavMail.app/Contents/Info-nodock.plist" match="&lt;key>CFBundleName&lt;/key>"
replace="&lt;key>LSUIElement&lt;/key>&lt;string>1&lt;/string>&lt;key>CFBundleName&lt;/key>"/>
<copy file="dist/DavMail.app/Contents/Info-nodock.plist" tofile="dist/DavMail.app/Contents/Info.plist" overwrite="true"/>
<!-- java 1.6 is mandatory for hide from dock -->
<replaceregexp file="dist/DavMail.app/Contents/Info-nodock.plist" match="1\.5" replace="1.6"/>
<replaceregexp file="dist/DavMail.app/Contents/Info.plist" match="&lt;key>CFBundleName&lt;/key>"
replace="&lt;key>LSUIElement&lt;/key>&lt;string>0&lt;/string>&lt;key>CFBundleName&lt;/key>"/>
<zip file="dist/DavMail-MacOSX-${release}.app.zip">
<zipfileset dir="dist">
<include name="DavMail.app/**/*"/>

View File

@ -0,0 +1,85 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2012 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.ui;
import davmail.util.IOUtil;
import org.apache.log4j.Logger;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* Handle OSX Info.plist file access
*/
public class OSXInfoPlist {
protected static final Logger LOGGER = Logger.getLogger(OSXInfoPlist.class);
protected static final String INFO_PLIST_PATH = "Contents/Info.plist";
protected static boolean isOSX() {
return System.getProperty("os.name").toLowerCase().startsWith("mac os x");
}
protected static String getInfoPlistContent() throws IOException {
FileInputStream fileInputStream = new FileInputStream(INFO_PLIST_PATH);
return new String(IOUtil.readFully(fileInputStream));
}
/**
* Test current LSUIElement (hide from dock) value
*
* @return true if application is hidden from dock
*/
public static boolean isHideFromDock() {
boolean result = false;
try {
result = isOSX() && getInfoPlistContent().indexOf("<key>LSUIElement</key><string>1</string>") >= 0;
} catch (IOException e) {
LOGGER.warn("Unable to update Info.plist", e);
}
return result;
}
/**
* Update LSUIElement (hide from dock) value
*
* @param hideFromDock new hide from dock value
*/
public static void setOSXHideFromDock(boolean hideFromDock) {
try {
if (isOSX()) {
boolean currentHideFromDock = isHideFromDock();
if (currentHideFromDock != hideFromDock) {
String content = getInfoPlistContent();
FileOutputStream fileOutputStream = new FileOutputStream(INFO_PLIST_PATH);
try {
fileOutputStream.write(content.replaceFirst(
"<key>LSUIElement</key><string>" + (currentHideFromDock ? "1" : "0") + "</string>",
"<key>LSUIElement</key><string>" + (hideFromDock ? "1" : "0") + "</string>").getBytes("UTF-8"));
} finally {
fileOutputStream.close();
}
fileOutputStream.close();
}
}
} catch (IOException e) {
LOGGER.warn("Unable to update Info.plist", e);
}
}
}

View File

@ -103,6 +103,8 @@ public class SettingsFrame extends JFrame {
JComboBox enableEwsComboBox;
JCheckBox smtpSaveInSentCheckBox;
JCheckBox osxHideFromDockCheckBox;
protected void addSettingComponent(JPanel panel, String label, JComponent component) {
addSettingComponent(panel, label, component, null);
}
@ -459,12 +461,24 @@ public class SettingsFrame extends JFrame {
addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_DISABLE_UPDATE_CHECK"), disableUpdateCheck,
BundleMessage.format("UI_DISABLE_UPDATE_CHECK_HELP"));
Dimension preferredSize = otherSettingsPanel.getPreferredSize();
preferredSize.width = Integer.MAX_VALUE;
updateMaximumSize(otherSettingsPanel);
return otherSettingsPanel;
}
protected JPanel getOSXPanel() {
JPanel osxSettingsPanel = new JPanel(new GridLayout(1, 2));
osxSettingsPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_OSX")));
osxHideFromDockCheckBox = new JCheckBox();
osxHideFromDockCheckBox.setSelected(OSXInfoPlist.isHideFromDock());
addSettingComponent(osxSettingsPanel, BundleMessage.format("UI_OSX_HIDE_FROM_DOCK"), osxHideFromDockCheckBox,
BundleMessage.format("UI_OSX_HIDE_FROM_DOCK_HELP"));
updateMaximumSize(osxSettingsPanel);
return osxSettingsPanel;
}
protected JPanel getLoggingSettingsPanel() {
JPanel loggingLevelPanel = new JPanel();
JPanel leftLoggingPanel = new JPanel(new GridLayout(2, 2));
@ -592,6 +606,10 @@ public class SettingsFrame extends JFrame {
wireLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("httpclient.wire"));
logFilePathField.setText(Settings.getProperty("davmail.logFilePath"));
logFileSizeField.setText(Settings.getProperty("davmail.logFileSize"));
if (osxHideFromDockCheckBox != null) {
osxHideFromDockCheckBox.setSelected(OSXInfoPlist.isHideFromDock());
}
}
protected boolean isSslEnabled() {
@ -674,6 +692,16 @@ public class SettingsFrame extends JFrame {
tabbedPane.add(BundleMessage.format("UI_TAB_ADVANCED"), advancedPanel);
if (OSXInfoPlist.isOSX()) {
JPanel osxPanel = new JPanel();
osxPanel.setLayout(new BoxLayout(osxPanel, BoxLayout.Y_AXIS));
osxPanel.add(getOSXPanel());
// empty panel
osxPanel.add(new JPanel());
tabbedPane.add(BundleMessage.format("UI_TAB_OSX"), osxPanel);
}
add(BorderLayout.CENTER, tabbedPane);
JPanel buttonPanel = new JPanel();
@ -751,6 +779,11 @@ public class SettingsFrame extends JFrame {
setVisible(false);
Settings.save();
if (osxHideFromDockCheckBox != null) {
OSXInfoPlist.setOSXHideFromDock(osxHideFromDockCheckBox.isSelected());
}
// restart listeners with new config
DavGateway.restart();
}

View File

@ -88,4 +88,14 @@ public final class IOUtil {
targetImage.getGraphics().drawImage(scaledImage, 0, 0, null);
return targetImage;
}
public static byte[] readFully(InputStream inputStream) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] bytes = new byte[8192];
int length;
while ((length = inputStream.read(bytes)) > 0) {
baos.write(bytes, 0, length);
}
return baos.toByteArray();
}
}

View File

@ -231,6 +231,10 @@ UI_SHOW_LOGS=Show logs...
UI_SMTP_PORT=Local SMTP port:
UI_SMTP_PORT_HELP=Local SMTP server port to configure in mail client
UI_TAB_ADVANCED=Advanced
UI_TAB_OSX=OSX
UI_OSX=OSX
UI_OSX_HIDE_FROM_DOCK=Hide from Dock
UI_OSX_HIDE_FROM_DOCK_HELP=Hide application from Dock (restart needed)
UI_TAB_ENCRYPTION=Encryption
UI_TAB_MAIN=Main
UI_TAB_NETWORK=Network

View File

@ -245,6 +245,10 @@ UI_CLIENT_KEY_STORE_HELP=Chemin du fichier contenant le certificat client SSL
UI_CLIENT_KEY_STORE_PASSWORD=Mot de passe certificat client :
UI_CLIENT_KEY_STORE_PASSWORD_HELP=Mot de passe du certificat client, laisser vide pour fournir le mot de passe mode interactif
UI_TAB_LOGGING=Traces
UI_TAB_OSX=OSX
UI_OSX=OSX
UI_OSX_HIDE_FROM_DOCK=Supprimer du Dock
UI_OSX_HIDE_FROM_DOCK_HELP=Supprimer l''application du Dock (redémarrage nécessaire)
UI_OTHER=Autres
UI_CALDAV_ALARM_SOUND=Son des alarmes Caldav :
UI_CALDAV_ALARM_SOUND_HELP=Convertir les alarmes Caldav en alarmes sonores supportées par iCal, par exemple Basso