Adding Linux Plugin.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@8921 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2007-08-10 22:44:58 +00:00
committed by derek
parent 26e2e57522
commit 4c2766aa9f
8 changed files with 633 additions and 1 deletions

View File

@ -11,7 +11,7 @@
<excludeFolder url="file://$MODULE_DIR$/../../src/plugins" /> <excludeFolder url="file://$MODULE_DIR$/../../src/plugins" />
<excludeFolder url="file://$MODULE_DIR$/../../target" /> <excludeFolder url="file://$MODULE_DIR$/../../target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="JDK 1.5.0" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" exported=""> <orderEntry type="module-library" exported="">
<library> <library>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4" relativePaths="true" type="JAVA_MODULE">
<component name="ModuleRootManager" />
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Spark" />
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
<option name="ACTIVE_VCS_NAME" value="svn" />
<option name="USE_PROJECT_VCS" value="false" />
</component>
</module>

View File

@ -0,0 +1,81 @@
<project name="Linux Plugin" default="jar" basedir="..">
<property name="plug.dir" value="${basedir}"/>
<property name="plug.lib.dir" value="${plug.dir}/build/lib"/>
<property name="classes.dir" value="${basedir}/build/classes"/>
<property name="src.dir" value="${plug.dir}/src"/>
<property name="java.dir" value="${src.dir}/java"/>
<property name="resources.dir" value="${src.dir}/resources"/>
<property name="target.dir" value="${plug.dir}/target"/>
<property name="target.lib.dir" value="${plug.dir}/target/lib"/>
<property name="jar.file" value="${target.dir}/lib/plugin-classes.jar"/>
<property name="spark.home" value="c:\code\spark"/>
<property name="spark.libs.dir" value="${spark.home}/target/build/lib"/>
<path id="lib.classpath">
<fileset dir="${spark.libs.dir}" includes="**/*.jar, **/*.zip"/>
<fileset dir="${spark.home}/build/lib/dist" includes="**/*.jar, **/*.zip"/>
<fileset dir="${spark.home}/build/lib/dist/windows" includes="**/*.jar"/>
</path>
<target name="clean" description="Cleans all build related output">
<delete file="${jar.file}"/>
<delete dir="${classes.dir}"/>
<delete dir="${target.dir}"/>
</target>
<target name="resources">
<copy todir="${classes.dir}">
<fileset dir="${resources.dir}">
<include name="**/*"/>
</fileset>
<fileset dir="${java.dir}">
<include name="**/*.properties"/>
</fileset>
</copy>
</target>
<target name="compile" description="Compiles plugin source">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${java.dir}"
destdir="${classes.dir}"
classpathref="lib.classpath"
source="1.5"
debug="true"
target="1.5"/>
<copy todir="${classes.dir}">
<fileset dir="${java.dir}" includes="**/*.png"/>
<fileset dir="${java.dir}" includes="**/*.gif"/>
<fileset dir="${java.dir}" includes="**/*.jpg"/>
<fileset dir="${java.dir}" includes="**/*.jpeg"/>
</copy>
</target>
<target name="jar" depends="clean, resources, compile" description="Makes a plugin jar">
<mkdir dir="${target.dir}"/>
<mkdir dir="${target.lib.dir}"/>
<copy todir="${target.dir}">
<fileset file="${plug.dir}/plugin.xml"/>
</copy>
<copy todir="${target.dir}">
<fileset dir="${plug.dir}">
<include name="**/*.html"/>
<include name="**/*.txt"/>
</fileset>
</copy>
<jar basedir="${classes.dir}" file="${jar.file}" update="false"/>
<zip zipfile="${target.dir}/transferguard.jar" basedir="${target.dir}"/>
</target>
</project>

View File

@ -0,0 +1,56 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>TransferGuard Spark Plug Log</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
padding-left : 1em;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>
Linux Plugin Change Log
</h1>
<p><b>1.0.0</b> -- August 10th, 2007</p>
<ul>
<li>Initial release.</li>
</ul>
</body>
</html>

View File

@ -0,0 +1,12 @@
<!-- Define your plugins -->
<plugin>
<name>Linux plugin for Spark IM Client</name>
<version>1.0</version>
<author>Derek DeMoro</author>
<homePage>http://www.jivesoftware.com</homePage>
<email>derek@jivesoftware.com</email>
<description>Adds Linux specific functionallity.</description>
<class>org.jivesoftware.spark.plugins.transfersettings.FileTransferSettingsPlugin</class>
<minSparkVersion>2.5.0</minSparkVersion>
</plugin>

View File

@ -0,0 +1,68 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Linux Spark Plug Readme</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
#datatable TH {
color : #fff;
background-color : #2A448C;
text-align : left;
}
#datatable TD {
background-color : #FAF6EF;
}
#datatable .name {
background-color : #DCE2F5;
}
</style>
</head>
<body>
<h1>
Linux Plugin Readme
</h1>
<h2>Overview</h2>
<p>
The plugin allows for Linux specific functionallity such as system tray.
</p>
<h2>Installation</h2>
<p>Simply install plugin via the Plugin Viewer in Spark</p>
</body>
</html>

View File

@ -0,0 +1,32 @@
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.spark.plugins;
import org.jivesoftware.spark.plugin.Plugin;
/**
*
*/
public class LinuxPlugin implements Plugin {
public void initialize() {
// Add System Tray
new LinuxSystemTray();
}
public void shutdown() {
}
public boolean canShutDown() {
return false;
}
public void uninstall() {
}
}

View File

@ -0,0 +1,363 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.spark.plugins;
import org.jivesoftware.MainWindow;
import org.jivesoftware.MainWindowListener;
import org.jivesoftware.Spark;
import org.jivesoftware.resource.Default;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.Workspace;
import org.jivesoftware.spark.component.ImageTitlePanel;
import org.jivesoftware.spark.component.WrappedLabel;
import org.jivesoftware.spark.ui.PresenceListener;
import org.jivesoftware.spark.ui.status.StatusBar;
import org.jivesoftware.spark.ui.status.StatusItem;
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Menu;
import java.awt.MenuItem;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
/**
* Handles tray icon operations inside of Spark. Use to display incoming chat requests, incoming messages
* and general notifications.
*/
public final class LinuxSystemTray implements ActionListener, MainWindowListener {
private SystemTray systemTray;
private TrayIcon trayIcon;
private JPopupMenu notificationDialog;
private WrappedLabel messageLabel = new WrappedLabel();
private final MenuItem openMenu = new MenuItem(Res.getString("menuitem.open"));
private final MenuItem hideMenu = new MenuItem(Res.getString("menuitem.hide"));
private final MenuItem exitMenu = new MenuItem(Res.getString("menuitem.exit"));
private final MenuItem logoutMenu = new MenuItem(Res.getString("menuitem.logout.no.status"));
// Define DND MenuItems
private final Menu statusMenu = new Menu(Res.getString("menuitem.status"));
private boolean isDisposed;
private ImageTitlePanel headerLabel = new ImageTitlePanel();
private JFrame hideWindow = null;
private ImageIcon availableIcon;
private ImageIcon awayIcon;
private ImageIcon dndIcon;
/**
* Creates a new instance of notifications.
*/
public LinuxSystemTray() {
setupNotificationDialog();
// Handle tray image.
availableIcon = Default.getImageIcon(Default.TRAY_IMAGE);
if (availableIcon == null) {
availableIcon = SparkRes.getImageIcon(SparkRes.TRAY_IMAGE);
}
awayIcon = SparkRes.getImageIcon(SparkRes.MESSAGE_AWAY);
dndIcon = SparkRes.getImageIcon(SparkRes.MESSAGE_DND);
trayIcon = new TrayIcon(availableIcon.getImage());
trayIcon.setImageAutoSize(true);
systemTray = SystemTray.getSystemTray();
setTrayIcon(availableIcon);
trayIcon.setToolTip(Default.getString(Default.APPLICATION_NAME)); // NORES
PopupMenu popupMenu = new PopupMenu(Res.getString("title.tray.information"));
// Add DND Menus
addStatusMenuItems();
// Add Open Menu
openMenu.setFont(new Font("Dialog", Font.BOLD, 11));
popupMenu.add(openMenu);
// Add Hide Menu
popupMenu.add(hideMenu);
popupMenu.addSeparator();
// Add Spark Home Menu
popupMenu.add(statusMenu);
// Add Listeners
openMenu.addActionListener(this);
hideMenu.addActionListener(this);
Action logoutAction = new AbstractAction() {
public void actionPerformed(ActionEvent actionEvent) {
SparkManager.getMainWindow().logout(false);
}
};
logoutAction.putValue(Action.NAME, Res.getString("menuitem.logout.no.status"));
logoutMenu.addActionListener(logoutAction);
if (Spark.isWindows()) {
popupMenu.add(logoutMenu);
}
// Add Exit Menu
popupMenu.add(exitMenu);
exitMenu.addActionListener(this);
SparkManager.getMainWindow().addMainWindowListener(this);
trayIcon.setPopupMenu(popupMenu);
try {
systemTray.add(trayIcon);
}
catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
return;
}
trayIcon.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
showMainWindow();
}
});
SparkManager.getSessionManager().addPresenceListener(new PresenceListener() {
public void presenceChanged(Presence presence) {
changePresence(presence);
}
});
}
/**
* Change the presence of the tray.
*
* @param presence the new presence.
*/
public void changePresence(Presence presence) {
if (Spark.isMac()) {
return;
}
if (presence.getMode() == Presence.Mode.available || presence.getMode() == Presence.Mode.chat) {
setTrayIcon(availableIcon);
}
else if (presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa) {
setTrayIcon(awayIcon);
}
else {
setTrayIcon(dndIcon);
}
// Get Status Text
if (presence.isAvailable()) {
String status = presence.getStatus();
trayIcon.setToolTip(Default.getString(Default.APPLICATION_NAME) + "\n" + status);
}
}
/**
* Stops the icon from flashing.
*/
public void stopFlashing() {
Workspace workspace = SparkManager.getWorkspace();
StatusBar statusBox = workspace.getStatusBar();
Presence presence = statusBox.getPresence();
changePresence(presence);
}
public void actionPerformed(ActionEvent e) {
Object o = e.getSource();
if (!(o instanceof MenuItem)) {
MainWindow window = SparkManager.getMainWindow();
/*
if (window.isVisible() && window.getState() == Frame.NORMAL) {
long now = System.currentTimeMillis();
if (now - madeVisibleTime > 1000) {
window.setVisible(false);
return;
}
}
madeVisibleTime = System.currentTimeMillis();
*/
showMainWindow();
return;
}
final MenuItem item = (MenuItem)e.getSource();
if (item == openMenu) {
showMainWindow();
}
else if (item == hideMenu) {
SparkManager.getMainWindow().setVisible(false);
hideMenu.setEnabled(false);
}
else if (item == exitMenu) {
isDisposed = true;
SparkManager.getMainWindow().shutdown();
}
else {
final String status = item.getLabel();
// Change Status
Workspace workspace = SparkManager.getWorkspace();
StatusItem statusItem = workspace.getStatusBar().getStatusItem(status);
if (statusItem != null) {
SparkManager.getSessionManager().changePresence(statusItem.getPresence());
}
}
}
/**
* Brings the <code>MainWindow</code> to the front.
*/
private void showMainWindow() {
if (hideWindow != null) {
hideWindow.dispose();
}
SparkManager.getMainWindow().setState(Frame.NORMAL);
SparkManager.getMainWindow().setVisible(true);
notificationDialog.setVisible(false);
hideMenu.setEnabled(true);
SparkManager.getMainWindow().toFront();
}
/**
* Add all Registered DND's to MenuItems.
*/
private void addStatusMenuItems() {
Workspace workspace = SparkManager.getWorkspace();
StatusBar statusBar = workspace.getStatusBar();
Iterator iter = statusBar.getStatusList().iterator();
while (iter.hasNext()) {
StatusItem item = (StatusItem)iter.next();
final MenuItem menuItem = new MenuItem(item.getText());
menuItem.addActionListener(this);
statusMenu.add(menuItem);
}
}
public void shutdown() {
systemTray.remove(trayIcon);
}
public void mainWindowActivated() {
}
public void mainWindowDeactivated() {
}
/**
* Setup notification dialog.
*/
private void setupNotificationDialog() {
notificationDialog = new JPopupMenu();
notificationDialog.setFocusable(false);
notificationDialog.setLayout(new BorderLayout());
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Point newLoc = new Point((int)screenSize.getWidth() - 200, (int)screenSize.getHeight() - 150);
JPanel mainPanel = new JPanel();
mainPanel.setBackground(Color.white);
mainPanel.setLayout(new GridBagLayout());
mainPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
// Add Header Label
mainPanel.add(headerLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
// Add Message Label
final JScrollPane messageScroller = new JScrollPane(messageLabel);
mainPanel.add(messageScroller, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
messageScroller.setBackground(Color.white);
messageScroller.setForeground(Color.white);
messageLabel.setBackground(Color.white);
messageScroller.getViewport().setBackground(Color.white);
// JButton okButton = new JButton("Ok");
mainPanel.setPreferredSize(new Dimension(200, 150));
headerLabel.setTitle("Spark"); // NORES
headerLabel.setTitleFont(new Font("Dialog", Font.BOLD, 10));
messageLabel.setFont(new Font("Dialog", Font.PLAIN, 11));
notificationDialog.add(mainPanel, BorderLayout.CENTER);
notificationDialog.pack();
notificationDialog.setPreferredSize(new Dimension(200, 150));
notificationDialog.setLocation(newLoc);
messageLabel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
notificationDialog.setVisible(false);
showMainWindow();
}
});
mainPanel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
notificationDialog.setVisible(false);
showMainWindow();
}
});
}
private void setTrayIcon(ImageIcon icon) {
trayIcon.setImage(icon.getImage());
}
}