Search in sources :

Example 1 with Preference

use of org.jivesoftware.spark.preference.Preference in project Spark by igniterealtime.

the class ReceiveFileTransfer method acceptFileTransfer.

public void acceptFileTransfer(final FileTransferRequest request) {
    String fileName = request.getFileName();
    long fileSize = request.getFileSize();
    String requestor = request.getRequestor();
    String bareJID = XmppStringUtils.parseBareJid(requestor);
    // SPARK-1869
    FileTransferNegotiator.getInstanceFor(SparkManager.getConnection());
    FileTransferNegotiator.IBB_ONLY = SettingsManager.getLocalPreferences().isFileTransferIbbOnly();
    ByteFormat format = new ByteFormat();
    String text = format.format(fileSize);
    fileLabel.setText(fileName + " (" + text + ")");
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    ContactItem contactItem = contactList.getContactItemByJID(bareJID);
    titleLabel.setText(Res.getString("message.user.is.sending.you.a.file", contactItem.getDisplayName()));
    File tempFile = new File(Spark.getSparkUserHome(), "/tmp");
    try {
        tempFile.mkdirs();
        File file = new File(tempFile, fileName);
        file.delete();
        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        out.write("a");
        out.close();
        imageLabel.setIcon(GraphicUtils.getIcon(file));
        // Delete temp file when program exits.
        file.delete();
    } catch (IOException e) {
        imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32));
        Log.error(e);
    }
    acceptButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            try {
                Downloads.checkDownloadDirectory();
                acceptRequest(request);
            } catch (Exception ex) {
                // this means there is a problem with the download directory
                try {
                    request.reject();
                } catch (SmackException.NotConnectedException e1) {
                    Log.warning("Unable to reject the request.", ex);
                }
                setBackground(new Color(239, 245, 250));
                acceptButton.setVisible(false);
                declineButton.setVisible(false);
                if (Downloads.getDownloadDirectory() == null) {
                    fileLabel.setText("");
                } else {
                    ResourceUtils.resLabel(fileLabel, null, Res.getString("label.transfer.download.directory") + " " + Downloads.getDownloadDirectory().getAbsolutePath());
                }
                // option to set a new path for the file-download
                pathButton.setVisible(true);
                pathButton.addMouseListener(new MouseAdapter() {

                    public void mousePressed(MouseEvent e) {
                        Preference p = SparkManager.getPreferenceManager().getPreference(new FileTransferPreference().getNamespace());
                        // retrieve the filetransfer preferences and show the preference menu
                        // to the user
                        SparkManager.getPreferenceManager().showPreferences(p);
                    }
                });
                titleLabel.setText(ex.getMessage());
                titleLabel.setForeground(new Color(65, 139, 179));
                invalidate();
                validate();
                repaint();
            }
        }
    });
    declineButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            rejectRequest(request);
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) FileWriter(java.io.FileWriter) SmackException(org.jivesoftware.smack.SmackException) Color(java.awt.Color) MouseAdapter(java.awt.event.MouseAdapter) ContactList(org.jivesoftware.spark.ui.ContactList) IOException(java.io.IOException) FileTransferPreference(org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference) SmackException(org.jivesoftware.smack.SmackException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ByteFormat(org.jivesoftware.spark.util.ByteFormat) FileTransferPreference(org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference) Preference(org.jivesoftware.spark.preference.Preference) File(java.io.File)

Example 2 with Preference

use of org.jivesoftware.spark.preference.Preference in project Spark by igniterealtime.

the class PreferencesPanel method selectionChanged.

private synchronized void selectionChanged() {
    PreferenceUI o = (PreferenceUI) list.getSelectedValue();
    Preference pref = o.getPreference();
    pref.load();
    JComponent comp = pref.getGUI();
    flowPanel.removeAll();
    // Create the title panel for this dialog
    TitlePanel titlePanel = new TitlePanel(pref.getTitle(), pref.getTooltip(), pref.getIcon(), false);
    flowPanel.add(comp, BorderLayout.CENTER);
    flowPanel.add(titlePanel, BorderLayout.NORTH);
    flowPanel.invalidate();
    flowPanel.validate();
    flowPanel.repaint();
    currentPreference = pref;
}
Also used : Preference(org.jivesoftware.spark.preference.Preference) JComponent(javax.swing.JComponent) TitlePanel(org.jivesoftware.spark.component.TitlePanel)

Example 3 with Preference

use of org.jivesoftware.spark.preference.Preference in project Spark by igniterealtime.

the class OTRPlugin method initialize.

@Override
public void initialize() {
    // Create OTRManager singleton
    _manager = OTRManager.getInstance();
    // The following will add an Entry into the Spark Preferences Window
    Preference mypreference = new OTRPreferences();
    SparkManager.getPreferenceManager().addPreference(mypreference);
}
Also used : OTRPreferences(org.jivesoftware.spark.otrplug.pref.OTRPreferences) Preference(org.jivesoftware.spark.preference.Preference)

Aggregations

Preference (org.jivesoftware.spark.preference.Preference)3 Color (java.awt.Color)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 JComponent (javax.swing.JComponent)1 SmackException (org.jivesoftware.smack.SmackException)1 TitlePanel (org.jivesoftware.spark.component.TitlePanel)1 FileTransferPreference (org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference)1 OTRPreferences (org.jivesoftware.spark.otrplug.pref.OTRPreferences)1 ContactItem (org.jivesoftware.spark.ui.ContactItem)1 ContactList (org.jivesoftware.spark.ui.ContactList)1 ByteFormat (org.jivesoftware.spark.util.ByteFormat)1